#import "WhiteScreenGame.h"

@interface WhiteScreenGame()

@property BOOL isWhite;
@property NSInteger remainigTime;
@property BOOL isGameOver;

@end

@implementation WhiteScreenGame

-(instancetype)init {
    self = [super init];
    if(self) {
        self.name = @"White Screen Game";
        self.type = reaction;
        self.ruleOfTheGame = @"Hit when white!";
    }
    return self;
}

-(void)onTick:(NSTimer *)timer {
    if (self.isGameOver == YES) {
        [timer invalidate];
    }
    else{
        self.remainigTime=self.remainigTime-1;
        if(self.remainigTime == 0) {
            [[NSNotificationCenter defaultCenter] postNotificationName:@"white" object:self userInfo:nil];
            self.isWhite = YES;
            [timer invalidate];
        }
    }
    
}

-(void) play {
    self.remainigTime = arc4random()%6+3;
    NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval: 1                                                  target: self selector:@selector(onTick:)userInfo: nil repeats:YES];
}

-(BOOL) isRight {
    return self.isWhite;
}

-(void)gameOver{
    self.isGameOver=YES;
}
@end
